package com.payment.controller;

import com.payment.bean.Payment;
import com.payment.service.PaymentService;
import com.payment.util.CommonResult;
import com.payment.util.RestSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description:
 *
 * @author weiruibai.vendor
 * Date: 2022/12/12 17:35
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private PaymentService paymentService;

    @Autowired
    private RestSupport support;

    @PostMapping(value = "/insert")
    public CommonResult insert(@RequestBody Payment payment) {
        return support.get(() -> paymentService.add(payment));
    }

    @GetMapping(value = "/get/{id}")
    public CommonResult get(@PathVariable("id") Integer id) {
        return support.get(() -> paymentService.get(id));
    }

    @GetMapping(value = "/gets")
    public CommonResult get() {
        return support.get(() -> paymentService.getList());
    }

    @GetMapping("/getPort")
    public String getEnvironment() {
        return port;
    }

}
